/*
 * @Author: ૮₍ ˙О˙₎ა
 * @Date: 2023-07-17 14:47:15
 */
import { reqGetCategory1, reqGetCategory2, reqGetCategory3 } from '@/api/attr'
import type { reqAttrCategory } from '@/types/attr'
import { defineStore } from 'pinia'

interface categoryStore {
  category1Id: string | number
  category2Id: string | number
  category3Id: string | number
  category1List: reqAttrCategory[]
  category2List: reqAttrCategory[]
  category3List: reqAttrCategory[]
}

const useAttrStore = defineStore('attrStore', {
  state: (): categoryStore => {
    return {
      category1Id: '',
      category2Id: '',
      category3Id: '',
      category1List: [],
      category2List: [],
      category3List: [],
    }
  },
  actions: {
    async getCategory1List() {
      const res = await reqGetCategory1()
      if (res.code === 200) {
        this.category1List = res.data
      }
    },

    async getCategory2List(id: number) {
      const res = await reqGetCategory2(id)

      if (res.code === 200) {
        this.category2List = res.data
      }
    },

    async getCategory3List(id: number) {
      const res = await reqGetCategory3(id)
      if (res.code === 200) {
        this.category3List = res.data
      }
    },
  },
})

export { useAttrStore }
